package com.asset.salesforce.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.asset.salesforce.domain.Comment;

@Repository
public class CommentDaoImpl {
	
	@Autowired
	SessionFactory sessionFactory;
	
	public void addcomment(Comment comment) {
		try{
			sessionFactory.getCurrentSession().save(comment);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	@SuppressWarnings("unchecked")
	public List<Comment> getAllcommentsByEmpId(Integer postId) {
		 Session session = sessionFactory.getCurrentSession();
		 Query query = session.createQuery("from comment c where c.post.id = :postId ");
		 query.setParameter("postId", postId);
		 List<Comment> comments = new ArrayList<Comment>(); 
		 comments = query.list();
		 return comments;  
	}

}
